#pragma once

#include <compl.h>

#include <ddblk/adep_dblk.h>
/* 填充内容(锁等待策略, 锁内存序) */
/* 定义lock 需要传入锁的输出函数 */
/* 怎么把一个函数的输出定义成输入 */
OU2INFUN(blkwait, lock)

#define DECL_LOCK(lockname)				\
SAI _##lockname##lock_t *_##lockname##_init(void *ptr, size_t size);\
SAI void *_##lockname##_destruct(_##lockname##lock_t *s);\
SAI bool_t _##lockname##_lock(_##lockname##lock_t *s, locktoken_t *ptoken, waitcnt_t cnt, \
	INFUN(lock, waitpolicy), const acq_ord_t order);\
SAI bool_t _##lockname##_unlock(_##lockname##lock_t *s, locktoken_t token, waitcnt_t cnt, \
	INFUN(lock, waitpolicy),  const rel_ord_t order);


#define DEF_LOCK(lockname, name, waitouf)	\
typedef _##lockname##lock_t name##lock_t;		\
typedef _##lockname##node_t name##node_t;		\
SAI lock_t *name##_init(void *ptr, size_t size){ return (lock_t *)_##lockname##_init(ptr, size); }\
SAI void *name##_destruct(lock_t *s){ return _##lockname##_destruct((name##lock_t *)s); }\
SAI bool_t name##_timed_lock(lock_t *l, locktoken_t *ptoken, waitcnt_t cnt){ return _##lockname##_lock((name##lock_t *)l, ptoken, cnt, waitouf, LACQ); }\
SAI bool_t name##_timed_unlock(lock_t *l, locktoken_t token, waitcnt_t cnt){ return _##lockname##_unlock((name##lock_t *)l, token, cnt, waitouf, RREL); }\
SAI bool_t name##_timed_lock_relax(lock_t *l, locktoken_t *ptoken, waitcnt_t cnt){ return _##lockname##_lock((name##lock_t *)l, ptoken, cnt, waitouf, LRLX); }\
SAI bool_t name##_timed_unlock_relax(lock_t *l, locktoken_t token, waitcnt_t cnt){ return _##lockname##_unlock((name##lock_t *)l, token, cnt, waitouf, RRLX); }\
SAI bool_t name##_lock(lock_t *l, locktoken_t *ptoken){ return name##_timed_lock(l, ptoken, -1); }\
SAI bool_t name##_unlock(lock_t *l, locktoken_t token){ return name##_timed_unlock(l, token, -1); }\
SAI bool_t name##_lock_relax(lock_t *l, locktoken_t *ptoken){ return name##_timed_lock_relax(l, ptoken, -1); }\
SAI bool_t name##_unlock_relax(lock_t *l, locktoken_t token){ return name##_timed_unlock_relax(l, token, -1); }\
MAY_UNUSED NEW_OUFUN(lock, name, name##_init, name##_destruct, name##_lock, name##_unlock, name##_lock_relax, name##_unlock_relax)\
MAY_UNUSED NEW_OUFUN(timed_lock, timed_##name, name##_init, name##_destruct, name##_timed_lock, name##_timed_unlock)
